new Vue({
    el: '#app',
    mixins: [Query],//组件配置文件，路径/utils/components.js
    data() {
        return {
            form: {//查询筛选
                value: '',
                PageNumber: 1, //页码
                RowAmount: 20,
                Condition: utf8ToBase64(`%%,%%`),
            },
        }
    },
    mounted() {
        /**
         * 组件配置文件中自动执行方法
         * 1.this.getColumn(); //查询表头数据
         * 2.this.getList(this.form); //查询表格数据
         * 3.this.getTreeData();//查询树
         */
    },
    methods: {
        handleCommand(cmd, row) {
            try {
                if (cmd === 'handleAdd') {
                    this.handleAdd(row);
                } else if (cmd === 'quoteRecords') {
                    const acqId = row.Acquisition_Unit_Price_SerialNumber;
                    window.location.href = `./list.html?acqId=${acqId}`;
                }
            } catch (error) {
                console.error(error);
                this.$message({ message: '系统错误，请联系开发者!', type: 'error' });
            }
        },
        handleSerach() { //筛选
            this.form.Condition = utf8ToBase64(`%${this.form.value}%`);
            this.form.PageNumber = 1;
            this.getList(this.form);
        },
        handleNodeClick(data, node) {
            const enterpriseId = data.Enterprise_Info_SerialNumber || '';

            // 管理员企业编号是 '1' 显示全部
            let extensionCondition = '';
            if (enterpriseId && enterpriseId !== '1') {
                extensionCondition = `AND acquisition_unitprice.Enterprise_Info_SerialNumber='${enterpriseId}'`;
            }

            this.form.ExtensionCondition = utf8ToBase64(extensionCondition);
            this.form.PageNumber = 1;
            this.getList(this.form);
        },
        getTreeData() {
            httpRequest({
                url: '/generalBusiness/generalQueryByTableName',
                data: {
                    Data: 'enterprise_info',
                    Condition: `Row_Status='0'`
                },
                type: 'GET'
            }).then(data => {
                this.treeData = data;
            }).catch(xhr => {
                this.$message.error('系统错误，请联系开发者!');
            })
        },
        handleAdd(row) { // 提交订单
            try {
                const { primaryKey } = $('#table').data('options');
                window.location.href = "./add.html?action=Add&nodeKey=" + row[primaryKey];
            } catch (error) {
                console.error(error);
                this.$message({
                    message: '系统错误，请联系开发者!',
                    type: 'error'
                })
            }
        },
        handleShow(row) { // 跳转到求购审核详情页
            try {
                const acqId = row.Acquisition_Unit_Price_SerialNumber || (row && row.Acquisition_Unit_Price_SerialNumber);
                if (acqId) {
                    // 进入求购审核详情页，按报价编号作为 serial 传参
                    window.location.href = `../acquisition_article/review_detail.html?serial=${encodeURIComponent(acqId)}`;
                }
            } catch (error) {
                console.error(error);
                this.$message({
                    message: '系统错误，请联系开发者!',
                    type: 'error'
                })
            }
        },
    }
})